package com.suray.wcs.service.core.util;


import com.suray.basic.wcs.path.core.Node;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Date;
import java.util.Random;

public class CommonUtil {

    public final static Integer PROCESSING_RGV_NO_NOT_NULL = 0;
    // 预分车不是空执行车辆是空
    public final static Integer PRE_PROCESSING_RGV_NO_NOT_NULL_PROCESSING_RGV_NO_NULL = 1;
    // 预分车是空执行车辆也是空
    public final static Integer PRE_PROCESSING_RGV_NO_NULL_PROCESSING_RGV_NULL = 2;
    // 预分车
    public final static Integer PRE_ASSIGN_RGV = 0;
    // 重新预分车
    public final static Integer RE_PRE_ASSIGN_RGV = 1;
    // 故障任务优先级
    public final static Integer PRIORITY_CODE_ERROR = 10001;
    // 避让状态任务优先级
    public final static Integer PRIORITY_CODE_AVOID_STATUS = 15000;
    // 生成的避让任务优先级
    public final static Integer PRIORITY_CODE_AVOID = 20001;
    public final static Integer PRIORITY_CODE_BACK_CONNECT = 19900;
    public final static Integer PRIORITY_CODE_BALANCE = 10000;
    public final static Integer PRIORITY_RE_TASK = 10010;
    public final static Integer PRIORITY_CODE_MANUAL = 20000;


    /**
     * 获取id
     *
     * @param
     * @return String id
     */
    public static String getId() {
        int flag = new Random().nextInt(999999);
        if (flag < 100000) {
            flag += 100000;
        }
        long time = Integer.parseInt(DateUtil.format(new Date(), "HHmmssS"));
        String id = (flag + time) + "";
        return id;
    }

    public static String toStackTrace(Exception e) {
        StringWriter sw = null;
        PrintWriter pw = null;
        try {
            sw = new StringWriter();
            pw = new PrintWriter(sw);
            e.printStackTrace(pw);
            pw.flush();
            sw.flush();
            return sw.toString();
        } catch (Exception ex) {
            return "";
        } finally {
            if (sw != null) {
                try {
                    sw.close();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            }
            if (pw != null) {
                pw.close();
            }
        }
    }
}
